﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 角色基础类
/// </summary>
[System.Serializable]
public class Character
{
    private static int idCounter;

    [SerializeField]
    public int id;

    [SerializeField]
    public string name;
    /// <summary>
    /// 血量
    /// </summary>
    [SerializeField]
    private float hp;
    /// <summary>
    /// 魔法量
    /// </summary>
    [SerializeField]
    public float mp;
    /// <summary>
    /// 攻击方法列表
    /// </summary>
    public int[] attackInfos;
    /// <summary>
    /// 上次攻击产生的伤害
    /// </summary>
    public float lastAttackValue;
    /// <summary>
    /// 上次使用的AttackID
    /// </summary>
    public int lastAttackID;

    /// <summary>
    /// 是否活着
    /// </summary>
    public bool alive = true;

    public RuntimeAnimatorController animatorController;

    public float Hp
    {
        get => hp;
        set
        {
            hp = value;
            if (hp <= 0)
            {
                hp = 0;
                alive = false;
            }
        }
    }

    /// <summary>
    /// 攻击
    /// </summary>
    /// <param name="target"></param>
    public virtual void Attack(Character target)
    {
        //foreach (var i in Attacks)
        //{
        //    i.Attack(target);
        //}
        //随机一个Attack 进行攻击
        int index = Random.Range(0, attackInfos.Length);
        IAttack attack = AttackFactory.Instance.GetAttack(attackInfos[index]);
        lastAttackValue = attack.Attack(target);
        lastAttackID = attackInfos[index];
        //Debug.Log(index);
    }

    public Character(string disName, float hp, float mp,RuntimeAnimatorController animatorController,int[] attacks)
    {
        id = idCounter++;
        name = disName;
        this.Hp = hp;
        this.mp = mp;
        this.animatorController = animatorController;
        attackInfos = attacks;
    }
}
